#ifndef CUSTOMTREECONTROL_H
#define CUSTOMTREECONTROL_H

//#include "precomp.h"

//#include <QWidget>
//#include <QStandardItemModel>
//#include <QSqlDatabase>
//#include <QSqlError>
//#include <QSqlQueryModel>
//#include <QSqlQuery>
//#include <QHBoxLayout>
//#include <QVBoxLayout>
//#include <QTreeView>
//#include <QMenu>

class CustomTreeControl : public QWidget
{
    Q_OBJECT
public:
    explicit CustomTreeControl(QWidget *parent = nullptr);

    QTreeView *m_treeView;
    QStandardItemModel *m_model;
    QMenu *m_contextMenu;
    QSqlDatabase m_db;
    QString m_treeTitle="标题";
    QString m_treeType="DnDiction";
    QString m_parentIcon=":Resource/icon/bill.svg";
    QString m_childIcon=":Resource/icon/bookmark-one.svg";
    int m_maxLevel;
    void initModel();
    void setTreeTitle(QString strTitle);
signals:

    void treeSelectedChanged(int nodeId);
    void treeDeleteNode(int nodeId);
private:
    void initUi();

    void loadTreeFromDb(QStandardItemModel *model);
    void addNode(const QModelIndex &parentIndex, const QString &nodeName);
    void updateNodeToDb(int nodeId, QString nodeName);
    void deleteNodeToDb(int nodeId);
    int insertNodeToDb(const QString nodePath, const QString nodeName);
    QString getParentPathFromDb(int parentId);
    void createRightPopMenu();

 private slots:
    void slotAddBrotherNode();
    void slotAddChildNode();
    void slotDeleteNode();
    void slotModifyNode();
    void slotRefleshNode();
    void slotCustomContextMenu(const QPoint &point);
    void slotSelectionChanged();
};

#endif // CUSTOMTREECONTROL_H
